#include <iostream>
#include <algorithm>
using namespace std;

const int N = 400010;

int n;
long long m;
int a[N], b[N], c[N];

int main() {

    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }

    for (int i = 0; i < n; ++i) {
        c[i] = a[i] + b[i];
    }

    int start = *min_element(a, a + n);
    int end = *min_element(c, c + n);

    int res = start;
    for (int i = start + 1; i <= end; ++i) {
        if (m >= i - 1) {
            res = i;
            m -= i - 1;
        } else {
            break;
        }
    }


    cout << res;

    return 0;
}